package com.bskj.kuaifu.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.bskj.common.bean.model.CodeType;
import com.bskj.common.bean.model.CodeValue;
import com.bskj.common.bean.model.PayInfo;
import com.bskj.common.bean.model.RefundInfo;
import com.bskj.common.bean.model.RefundInfoDetail;
import com.bskj.common.bean.model.UserAppeal;
import com.bskj.common.bean.model.UserCar;
import com.bskj.common.bean.model.UserInfo;
import com.bskj.common.bean.model.UserMoneyLog;
import com.bskj.common.bean.model.UserThirdAuth;
import com.bskj.common.bean.vo.NoSenseParkingUserStatusReqVo;
import com.bskj.common.constants.CommonConstatns;
import com.bskj.common.dao.CodeTypeDao;
import com.bskj.common.dao.CodeValueDao;
import com.bskj.common.dao.RefundInfoDao;
import com.bskj.common.dao.RefundInfoDetailDao;
import com.bskj.common.dao.UserAppealDao;
import com.bskj.common.dao.UserCarDao;
import com.bskj.common.dao.UserInfoDao;
import com.bskj.common.dao.UserMoneyLogDao;
import com.bskj.common.dao.UserThirdAuthDao;
import com.bskj.common.dao.core.BaseDao;
import com.bskj.common.dao.core.FindRequestEntity;
import com.bskj.common.dao.core.OrderEnum;
import com.bskj.common.dao.core.WhereEnum;
import com.bskj.common.enums.UserAppealStausEnum;
import com.bskj.common.exception.DataErrorException;
import com.bskj.common.service.impl.BaseServiceImpl;
import com.bskj.common.utils.EncryptUtil;
import com.bskj.common.utils.LogUtils;
import com.bskj.common.utils.NoSensePayUtils;
import com.bskj.common.utils.StringUtils;
import com.bskj.kuaifu.bean.vo.req.UserReqVo;
import com.bskj.kuaifu.bean.vo.resp.UserMyMoneyDetailRespVo;
import com.bskj.kuaifu.bean.vo.resp.UserUnPayDetailRespVo;
import com.bskj.kuaifu.cache.redis.string.PhoneCodeCache;
import com.bskj.kuaifu.service.IParkInfoService;
import com.bskj.kuaifu.service.IPayInfoService;
import com.bskj.kuaifu.service.IUserInfoService;
import com.github.wxpay.sdk.WXPay;

/**
 * 
 * @author lishi
 * @date 2018年6月6日 下午11:41:58
 */
@Service
public class UserInfoServiceImpl extends BaseServiceImpl<UserInfo> implements IUserInfoService {
	@Autowired
	private UserInfoDao userInfoDao;

	@Autowired
	private UserCarDao userCarDao;

	@Autowired
	private PhoneCodeCache phoneCodeCache;

	@Autowired
	private IParkInfoService parkInfoService;

	@Autowired
	private WXPay wxPay;

	@Autowired
	private IPayInfoService payInfoService;

	@Autowired
	private RefundInfoDao refundInfoDao;

	@Autowired
	private RefundInfoDetailDao refundInfoDetailDao;

	@Autowired
	private UserMoneyLogDao userMoneyLogDao;

	@Autowired
	private CodeValueDao codeValueDao;

	@Autowired
	private CodeTypeDao codeTypeDao;

	@Autowired
	private UserAppealDao userAppealDao;

	@Autowired
	private UserThirdAuthDao userThirdAuthDao;

	public BaseDao<UserInfo> getBaseDao() {
		return userInfoDao;
	}

	@Override
	public UserInfo getUserInfoByCarNo(String appid, String carNo) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("car_no", WhereEnum.EQ, carNo);
		findReq.addWhere("appid", WhereEnum.EQ, appid);
		List<UserCar> userInfoList = userCarDao.find(findReq);
		if (userInfoList != null && userInfoList.size() > 0) {
			return get(userInfoList.get(0).getUserId());
		}
		return null;
	}

	@Override
	public UserInfo getUserInfoByOpenId(String openId) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("openid", WhereEnum.EQ, openId);
		List<UserInfo> userInfoList = find(findReq);
		if (userInfoList != null && userInfoList.size() > 0) {
			return userInfoList.get(0);
		}
		return null;
	}

	@Override
	public UserInfo getUserInfoByPhone(String phone) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("phone", WhereEnum.EQ, phone);
		List<UserInfo> userInfoList = find(findReq);
		if (userInfoList != null && userInfoList.size() > 0) {
			return userInfoList.get(0);
		}
		return null;
	}

	@Override
	public Map<String, String> register(UserReqVo userReqVo) throws Exception {
		Map<String, String> resultMap = new HashMap<>();
		String verifyNo = userReqVo.getVerifyNo();
		String phoneNo = userReqVo.getPhoneNo();
		if (!StringUtils.isBank(verifyNo) && !StringUtils.isBank(phoneNo)) {
			String serverVerifyNo = phoneCodeCache.get(phoneNo);
			LogUtils.debug("serverVerifyNo:" + serverVerifyNo);
			if (!verifyNo.equals(serverVerifyNo)) {
				resultMap.put("error", "验证码错误");
				return resultMap;
			}
		}

		boolean isNew = true;
		UserInfo userinfo = null;
		if (StringUtils.isBank(userReqVo.getUserId())) {
			userinfo = new UserInfo();
			if (!StringUtils.isBank(userReqVo.getAppId())) {
				userinfo.setAppId(userReqVo.getAppId());
			}
			if (!StringUtils.isBank(userReqVo.getOpenId())) {
				userinfo.setOpenId(userReqVo.getOpenId());
			}
			if (!StringUtils.isBank(userReqVo.getPhoneNo())) {
				userinfo.setPhone(userReqVo.getPhoneNo());
			}
			if (!StringUtils.isBank(userReqVo.getName())) {
				userinfo.setName(userReqVo.getName());
			}
			if (!StringUtils.isBank(userReqVo.getImage())) {
				userinfo.setImage(userReqVo.getImage());
			}

			userinfo.setUpdateTime(new Date());
		} else {
			userinfo = get(Integer.parseInt(userReqVo.getUserId()));
			if (userinfo != null) {
				isNew = false;
			}
		}

		if (isNew) {
			userinfo.setMoney(0);
			userinfo.setCreateTime(new Date());
			try {
				userInfoDao.insert(userinfo);
			} catch (DuplicateKeyException e) {
				resultMap.put("error", "号码已经绑定");
				return resultMap;
			}
		} else {
			if (!StringUtils.isBank(userReqVo.getPhoneNo())) {
				userinfo.setPhone(userReqVo.getPhoneNo());
			}
			userinfo.setUpdateTime(new Date());
			userInfoDao.update(userinfo);
		}

		return resultMap;
	}

	// private boolean isExistPhone(String phoneNo) throws Exception {
	// FindRequestEntity findReq = new FindRequestEntity();
	// findReq.addWhere("phone", WhereEnum.EQ, phoneNo);
	// List<UserInfo> userInfoList = find(findReq);
	// if (userInfoList != null && userInfoList.size() > 0) {
	// return true;
	// }
	// return false;
	// }

	/**
	 * 一个车牌只可以绑定一个微信公众号
	 */
	@Override
	public Map<String, Object> bindCarNo(String openid, String plateNumber) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("openid", WhereEnum.EQ, openid);
		List<UserThirdAuth> userThirdAuthList = userThirdAuthDao.find(findReq);
		if (userThirdAuthList != null && userThirdAuthList.size() > 0) {
			findReq = new FindRequestEntity();
			findReq.addWhere("car_no", WhereEnum.EQ, plateNumber);
			List<UserCar> userCarList = userCarDao.find(findReq);
			if (userCarList != null && userCarList.size() > 0) {
				if(userCarList.get(0).getStatus() == 0){
					userCarDao.del(userCarList.get(0).getId());
				}else {
					resultMap.put("success", false);
					resultMap.put("meg", "该车牌已被其它用户绑定，如需找回请联系公众号客服");
					return resultMap;
				}
			}
			UserCar userCar = new UserCar();
			userCar.setAppid("wxa5337aa97b8fea09");
			userCar.setCarNo(plateNumber);
			userCar.setUserId(userThirdAuthList.get(0).getUserId());
			userCar.setCreateTime(new Date());
			userCar.setUpdateTime(new Date());
			userCarDao.insert(userCar);
			resultMap.put("success", true);
			return resultMap;
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> bindCarNoGZ(Integer userId, String plateNumber) throws Exception {
		FindRequestEntity findReq=new FindRequestEntity();
		findReq.addWhere("car_no", WhereEnum.EQ, plateNumber);
		List<UserCar> userCarList=userCarDao.find(findReq);
		if(userCarList != null && userCarList.size() > 0){
			if(userCarList.get(0).getStatus() == 0){
				userCarDao.del(userCarList.get(0).getId());
			}else {
				throw new Exception();
			}
		}
		Map<String, Object> resultMap = new HashMap<>();
		UserCar userCar = new UserCar();
		userCar.setAppid("wxa5337aa97b8fea09");
		userCar.setCarNo(plateNumber);
		userCar.setUserId(userId);
		userCar.setCreateTime(new Date());
		userCar.setUpdateTime(new Date());
		userCarDao.insert(userCar);
		resultMap.put("success", true);
		return resultMap;

	}

	public UserMyMoneyDetailRespVo getMyMoneyDetail(Integer userId) throws Exception {
		UserInfo userInfo = get(userId);
		if (userInfo == null) {
			return null;
		}
		UserMyMoneyDetailRespVo resoVo = new UserMyMoneyDetailRespVo();
		resoVo.setUserInfo(userInfo);

		UserUnPayDetailRespVo unpayDetail = parkInfoService.getUnPayDetail(userId);
		resoVo.setUnpayDetail(unpayDetail);

		return resoVo;
	}

	@Override
	public UserInfo getUserInfoByUnionidId(String unionid) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("unionid", WhereEnum.EQ, unionid);
		List<UserInfo> userInfoList = find(findReq);
		if (userInfoList != null && userInfoList.size() > 0) {
			return userInfoList.get(0);
		}
		return null;
	}

	@Override
	public Map<String, Object> updateUserAndCarInfo(String appid, String openid, String carNo, String unionid)
			throws Exception {
		/*
		 * TODO 1、此处疑点： 这个openid到底是用户在车主服务平台下的appid 还是用户在车场公众号下的openid？？？
		 * 如果是车主服务平台下的openid ，此处逻辑错误，需要调整
		 */
		Map<String, Object> resultMap = new HashMap<>();
		UserInfo userInfo = getUserInfoByOpenId(unionid);
		if (userInfo == null) {
			// 如果用户不存在，新增用户，并绑定车牌
			userInfo = new UserInfo();
			userInfo.setAppId(appid);
			userInfo.setOpenId(openid);
			userInfo.setUnionid(unionid);
			userInfo.setCreateTime(new Date());
			userInfo.setUpdateTime(new Date());
			insert(userInfo);
		}
		// 如果用户已经存在，更新车牌信息
		UserCar userCar = getCarNo(appid, carNo);
		if (userCar != null) {
			if (userCar.getUserId().equals(userInfo.getId())) {
				// 如果车牌没有更换绑定人，忽略
			} else {
				// 车牌更换绑定人
				userCar.setUserId(userInfo.getId());
				userCar.setUpdateTime(new Date());
				userCarDao.update(userCar);
			}
		} else {
			// 车牌没有被绑定
			userCar = new UserCar();
			userCar.setCarNo(carNo);
			userCar.setAppid(appid);
			userCar.setUserId(userInfo.getId());
			userCar.setCreateTime(new Date());
			userCar.setUpdateTime(new Date());
			userCarDao.insert(userCar);
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> delCarNo(String openid, String plateNumber) throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("openid", WhereEnum.EQ, openid);
		List<UserThirdAuth> userThirdAuthList = userThirdAuthDao.find(findReq);
		if (userThirdAuthList != null && userThirdAuthList.size() > 0) {
			findReq = new FindRequestEntity();
			findReq.addWhere("user_id", WhereEnum.EQ, userThirdAuthList.get(0).getUserId());
			findReq.addWhere("car_no", WhereEnum.EQ, plateNumber);
			List<UserCar> userCarList = userCarDao.find(findReq);
			if (userCarList != null && userCarList.size() > 0) {
				if (userCarList.get(0).getStatus() == 0) {
					userCarDao.del(userCarList.get(0).getId());
				} else {
					resultMap.put("success", false);
					resultMap.put("meg", "对不起，删除之前请先关闭此车牌的无感支付功能！");
					return resultMap;
				}
				resultMap.put("success", true);
			}
		}
		return resultMap;
	}

	@Override
	public List<UserCar> getMyCarNo(Integer userId) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("user_id", WhereEnum.EQ, userId);
		return userCarDao.find(findReq);
	}

	@Override
	public UserCar getCarNo(String appid, String carNo) throws Exception {
		FindRequestEntity findReq = new FindRequestEntity();
		findReq.addWhere("car_no", WhereEnum.EQ, carNo);
		findReq.addWhere("appid", WhereEnum.EQ, appid);
		List<UserCar> userCarList = userCarDao.find(findReq);
		if (userCarList != null && userCarList.size() > 0) {
			return userCarList.get(0);
		}
		return null;
	}

	@Override
	public Map<String, Object> queryUserNoSenseStatus(Integer userId, String openid, String plateNumber)
			throws Exception {
		Map<String, Object> resultMap = new HashMap<>();
		NoSenseParkingUserStatusReqVo userStatusReqVo = new NoSenseParkingUserStatusReqVo("1012526397677109248",
				"WECHAT", "MD5", "F3B2E91B5689E63AA34465FA7D33DFEC");
		userStatusReqVo.setNotifyUrl("https://kuaifu.boshukeji.com/api/noSensePayNotify");
		userStatusReqVo.setTradeScene("PARKING");
		userStatusReqVo.setMchId("1508738031");
		userStatusReqVo.setSubOpenId(openid);
		userStatusReqVo.setPlateNumber(plateNumber);
		Map<String, Object> respone = NoSensePayUtils.queryUserStatus(userStatusReqVo);
		resultMap.put("queryResult", respone);
		if (respone != null && (boolean) respone.get("result")) {
			String data = EncryptUtil.deBase64((String) respone.get("data"));
			JSONObject dataJson = JSONObject.parseObject(data);

			if (userId != null && userId != 0) {
				// 根据查询结果更新 用户绑定车牌相关信息
				String plateNumberListStr = dataJson.getString("plateNumberList");
				if (!StringUtils.isBank(plateNumberListStr)) {
					String[] plateNumberList = dataJson.getString("plateNumberList").split(";");
					List<String> carNumList = new ArrayList<>();
					carNumList.addAll(Arrays.asList(plateNumberList));

					// 更新用户最新绑定车牌的信息
					List<UserCar> existCarNos = getMyCarNo(userId); // 已经在数据库里面的车牌号
					for (UserCar userCar : existCarNos) {
						if (!carNumList.contains(userCar.getCarNo())) {
							// 删除掉所有 没有绑定的车牌
							userCar.setStatus(0);
							userCar.setUpdateTime(new Date());
							userCarDao.update(userCar);
						} else {
							userCar.setStatus(1);
							userCar.setUpdateTime(new Date());
							userCarDao.update(userCar);
							carNumList.remove(userCar.getCarNo());
						}
					}

					// 新增没有保存到数据库的车牌
					for (String carNo : carNumList) {
						FindRequestEntity findReq = new FindRequestEntity();
						findReq.addWhere("car_no", WhereEnum.EQ, carNo);
						findReq.addWhere("user_id", WhereEnum.NE, userId);
						List<UserCar> userCarList = userCarDao.find(findReq);
						if (userCarList != null && userCarList.size() > 0) {
							for (UserCar userCar : userCarList) {
								userCarDao.del(userCar.getId());
								/*
								 * TODO 删除别人的车牌，要发送模板消息
								 */
							}
						}
						UserCar userCar = new UserCar();
						userCar.setUserId(userId);
						userCar.setAppid(CommonConstatns.KUAIFU_WX_APPID);
						userCar.setCarNo(carNo);
						userCar.setStatus(1);
						userCar.setCreateTime(new Date());
						userCar.setUpdateTime(new Date());
						userCarDao.insert(userCar);
					}
					resultMap.put("carList", getMyCarNo(userId));
				} else {
					// 同步车牌信息,即删除t_user_car中绑定的车牌信息
					FindRequestEntity findReq = new FindRequestEntity();
					findReq.addWhere("user_id", WhereEnum.EQ, userId);
					List<UserCar> userCarList = userCarDao.find(findReq);
					if (userCarList != null && userCarList.size() > 0) {
						userCarDao.updateStatus(userId);
					}
				}
				List<UserCar> existCarNos = getMyCarNo(userId);
				dataJson.put("existCarNos", existCarNos);
				resultMap.put("queryResult", dataJson);
			}
		}
		return resultMap;
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public Map<String, Object> withdrawCash(Integer userId) throws Exception {
		/**
		 * 提现逻辑
		 *
		 * 1、账户余额如果大于0才能提现，记录提现申请记录 2、找出用户没有退款完的支付定单（t_pay_info，remain_money >
		 * 0的），依次退款，退足提现金额为止 3、更新用余额
		 */
		// TODO 没有处理的异常问题 1、用户账户金额异常（金额不正常） 2、提现失败后续处理
		List<PayInfo> mqPayInfos = new ArrayList<>();

		Map<String, Object> resultMap = new HashMap<String, Object>();
		UserInfo userInfo = userInfoDao.get(userId);
		if (userInfo == null) {
			resultMap.put("result", false);
			resultMap.put("msg", "用户不存在");
		} else {
			if (userInfo.getMoney() <= 0) {
				resultMap.put("result", false);
				resultMap.put("msg", "用户余额不足，不能提现");
			} else {
				int money = userInfo.getMoney();
				/*
				 * step 1 : 记录提现申请
				 */
				RefundInfo refundInfo = new RefundInfo();
				refundInfo.setRefundMoney(money);
				refundInfo.setStatus(0);
				refundInfo.setUserId(userId);
				refundInfo.setCreateTime(new Date());
				refundInfo.setUpdateTime(new Date());
				refundInfoDao.insert(refundInfo);
				LogUtils.debug("refundInfo:" + JSONObject.toJSONString(refundInfo));

				/*
				 * step 2、找出用户没有退款完的支付定单（t_pay_info，remain_money >
				 * 0的），依次退款，退足提现金额为止
				 */
				while (money > 0) {
					FindRequestEntity findReq = new FindRequestEntity();
					findReq.addWhere("user_id", WhereEnum.EQ, userInfo.getId());
					findReq.addWhere("status", WhereEnum.EQ, 1);
					findReq.addWhere("remain_money", WhereEnum.GT, 0);

					findReq.addOrder("create_time", OrderEnum.DESC);

					findReq.setPage(1, 1);
					List<PayInfo> payInfoList = payInfoService.find(findReq);
					LogUtils.debug("payInfoList:" + JSONObject.toJSONString(payInfoList));
					if (payInfoList != null && payInfoList.size() > 0) {
						PayInfo payInfo = payInfoList.get(0);

						// 计算该订单可提现的金额 money[单位:角] refundMoney[单位:分]
						int refundMoney = money * 10;
						refundMoney = refundMoney > payInfo.getRemainMoney() ? payInfo.getRemainMoney() : refundMoney;
						LogUtils.debug("money:" + money + ",refundMoney:" + refundMoney);
						money = money - refundMoney / 10;
						LogUtils.debug("money:" + money);
						payInfo.setRefundMoney(payInfo.getRefundMoney() + refundMoney);
						payInfo.setRemainMoney(payInfo.getTotalFee() - payInfo.getRefundMoney());
						payInfo.setRefundFee(refundMoney);
						payInfo.setRefundInfoId(refundInfo.getId());
						// 退款订单，将订单订单放在rabbitMQ 的队列
						mqPayInfos.add(payInfo);
						// refund(payInfo);
					} else {
						String errorMsg = String.format("用户【%s】账户金额有问题", userInfo.getId());
						LogUtils.error(errorMsg);
						throw new DataErrorException(errorMsg);
					}
				}

				/*
				 * step 3、更新用户余额，记录日志
				 */
				int beforeMoney = userInfo.getMoney();
				int beforeCoupon = userInfo.getCoupon();
				LogUtils.debug("userInfo:" + JSONObject.toJSONString(userInfo));
				userInfo.setMoney(0);
				userInfo.setCoupon(0);
				int i = userInfoDao.update(userInfo);
				if (i == 1) {
					UserMoneyLog userMoneyLog = new UserMoneyLog();
					userMoneyLog.setUserId(userId);
					userMoneyLog.setChangeType(2);
					userMoneyLog.setRefundInfoId(refundInfo.getId());
					userMoneyLog.setBeforeMoney(beforeMoney);
					userMoneyLog.setChangeMoney(beforeMoney);
					userMoneyLog.setAfterMoney(0);
					userMoneyLog.setBeforeCoupon(beforeCoupon);
					userMoneyLog.setChangeCoupon(beforeCoupon);
					userMoneyLog.setAfterCoupon(0);
					LogUtils.debug("userMoneyLog:" + JSONObject.toJSONString(userMoneyLog));
					userMoneyLogDao.insert(userMoneyLog);
				}

				refundInfo.setStatus(1);
				refundInfoDao.update(refundInfo);

				resultMap.put("result", true);
				resultMap.put("msg", "提现成功");

			}
		}

		// if (mqPayInfos != null && mqPayInfos.size() >= 1) {
		// for (PayInfo payInfo : mqPayInfos) {
		// amqpTemplate.convertAndSend("refundKey", payInfo);
		// }
		// }

		return resultMap;
	}

	/**
	 * 退款单笔充值记录
	 *
	 * @param payInfo
	 * @return
	 * @throws Exception
	 */
	@Transactional(rollbackFor = Exception.class)
	public Map<String, String> refund(PayInfo payInfo) throws Exception {
		LogUtils.debug("payInfo:" + JSONObject.toJSONString(payInfo));
		Map<String, String> requestData = new HashMap<String, String>();
		String refundNo = StringUtils.getRandomWithTimestamp(32);
		payInfo.setRefundInfoNo(refundNo);
		requestData.put("out_trade_no", payInfo.getOrderNo());
		requestData.put("out_refund_no", payInfo.getRefundInfoNo());
		requestData.put("total_fee", payInfo.getTotalFee() + "");
		requestData.put("refund_fee", payInfo.getRefundFee() + "");
		LogUtils.debug("requestData:" + JSONObject.toJSONString(requestData));

		Map<String, String> resultMap = wxPay.refund(requestData);
		LogUtils.debug("wxPay.refund.resultMap:" + JSONObject.toJSONString(resultMap));
		if (resultMap.get("return_code").equals("SUCCESS") && resultMap.get("result_code").equals("SUCCESS")) {
			setRefundInfoDetail(payInfo);
		}
		return resultMap;
	}

	/**
	 * 新增数据退款记录，更新付款信息
	 *
	 * @param payInfo
	 * @throws Exception
	 */
	public void setRefundInfoDetail(PayInfo payInfo) throws Exception {
		RefundInfoDetail refundInfoDetail = new RefundInfoDetail();
		refundInfoDetail.setUserId(payInfo.getUserId());
		refundInfoDetail.setRefundInfoId(payInfo.getRefundInfoId());
		refundInfoDetail.setPayOrderNo(payInfo.getOrderNo());
		refundInfoDetail.setTotalFee(payInfo.getTotalFee());
		refundInfoDetail.setRefundMoney(payInfo.getRefundMoney());
		refundInfoDetail.setRemainMoney(payInfo.getRemainMoney());
		refundInfoDetail.setOrderNo(payInfo.getRefundInfoNo());
		refundInfoDetail.setStatus(1);
		LogUtils.debug("refundInfoDetail:" + JSONObject.toJSONString(refundInfoDetail));
		refundInfoDetailDao.insert(refundInfoDetail);
		payInfoService.update(payInfo);
	}

	@Override
	public List<CodeValue> findAppealType() throws Exception {
		FindRequestEntity findRequest = new FindRequestEntity();
		findRequest.addWhere("code", WhereEnum.EQ, "appealType");
		List<CodeType> list = codeTypeDao.find(findRequest);
		List<CodeValue> codeValues = new ArrayList<>();
		if (list.size() == 1) {
			FindRequestEntity findRequestv = new FindRequestEntity();
			findRequestv.addWhere("type_id", WhereEnum.EQ, list.get(0).getId());
			findRequestv.addOrder("orders", OrderEnum.ASC);
			codeValues = codeValueDao.find(findRequestv);
		}
		return codeValues;
	}

	@Override
	public void insertAppeal(UserAppeal userAppeal) throws Exception {
		userAppeal.setStatus(UserAppealStausEnum.complaint.getKey());
		userAppeal.setCreateTime(new Date());
		userAppeal.setUpdateTime(new Date());
		userAppealDao.insert(userAppeal);
	}

	public static void main(String[] args) {
		String[] cars = new String[] { "123", "234", "324" };
		List<String> carNumList = new ArrayList<>();
		carNumList.addAll(Arrays.asList(cars));
		System.out.println(carNumList);
		System.out.println(carNumList.contains("123"));
		carNumList.remove("123");
		System.out.println(carNumList.contains("123"));
		System.out.println(carNumList);
	}
}
